/*
 Navicat Premium Data Transfer

 Source Server         : localhost
 Source Server Type    : MySQL
 Source Server Version : 80021
 Source Host           : localhost:3306
 Source Schema         : youdian

 Target Server Type    : MySQL
 Target Server Version : 80021
 File Encoding         : 65001

 Date: 26/09/2020 21:31:41
*/

SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;

-- ----------------------------
-- Table structure for authorities
-- ----------------------------
DROP TABLE IF EXISTS `authorities`;
CREATE TABLE `authorities` (
  `username` varchar(50) NOT NULL COMMENT '用户名',
  `authority` varchar(50) NOT NULL COMMENT '权限',
  UNIQUE KEY `username_authorty` (`username`,`authority`) USING BTREE,
  CONSTRAINT `authorities_ibfk_1` FOREIGN KEY (`username`) REFERENCES `users` (`username`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='用户权限表';

-- ----------------------------
-- Records of authorities
-- ----------------------------
BEGIN;
INSERT INTO `authorities` VALUES ('admin', 'ROLE_ADMIN');
COMMIT;

-- ----------------------------
-- Table structure for group_authorities
-- ----------------------------
DROP TABLE IF EXISTS `group_authorities`;
CREATE TABLE `group_authorities` (
  `group_id` bigint NOT NULL COMMENT '用户组编号',
  `authority` varchar(50) NOT NULL COMMENT '权限',
  UNIQUE KEY `group_id_authorty` (`group_id`,`authority`) USING BTREE,
  CONSTRAINT `group_authorities_ibfk_1` FOREIGN KEY (`group_id`) REFERENCES `user_groups` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='分组权限表';

-- ----------------------------
-- Records of group_authorities
-- ----------------------------
BEGIN;
INSERT INTO `group_authorities` VALUES (14, 'ROLE_USER');
COMMIT;

-- ----------------------------
-- Table structure for group_members
-- ----------------------------
DROP TABLE IF EXISTS `group_members`;
CREATE TABLE `group_members` (
  `id` bigint NOT NULL AUTO_INCREMENT,
  `username` varchar(50) NOT NULL COMMENT '用户名',
  `group_id` bigint NOT NULL COMMENT '分组编号',
  PRIMARY KEY (`id`),
  UNIQUE KEY `unique_group_members_group_username` (`username`,`group_id`),
  KEY `fk_group_members_group` (`group_id`),
  KEY `fk_group_members_username` (`username`) USING BTREE,
  CONSTRAINT `group_members_ibfk_1` FOREIGN KEY (`group_id`) REFERENCES `user_groups` (`id`),
  CONSTRAINT `group_members_ibfk_2` FOREIGN KEY (`username`) REFERENCES `users` (`username`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=88 DEFAULT CHARSET=utf8 COMMENT='用户组成员表';

-- ----------------------------
-- Records of group_members
-- ----------------------------
BEGIN;
INSERT INTO `group_members` VALUES (15, 'admin', 14);
COMMIT;

-- ----------------------------
-- Table structure for user_groups
-- ----------------------------
DROP TABLE IF EXISTS `user_groups`;
CREATE TABLE `user_groups` (
  `id` bigint NOT NULL AUTO_INCREMENT,
  `group_name` varchar(50) NOT NULL COMMENT '用户组名称',
  `parent_id` bigint DEFAULT NULL,
  `manager` varchar(50) DEFAULT NULL COMMENT '组管理员',
  PRIMARY KEY (`id`),
  UNIQUE KEY `unique_groups_0` (`group_name`),
  KEY `fk_grooups_0` (`parent_id`),
  CONSTRAINT `user_groups_ibfk_1` FOREIGN KEY (`parent_id`) REFERENCES `user_groups` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=42 DEFAULT CHARSET=utf8 COMMENT='用户组表';

-- ----------------------------
-- Records of user_groups
-- ----------------------------
BEGIN;
INSERT INTO `user_groups` VALUES (14, '管理员群', NULL, NULL);
COMMIT;

-- ----------------------------
-- Table structure for users
-- ----------------------------
DROP TABLE IF EXISTS `users`;
CREATE TABLE `users` (
  `username` varchar(50) NOT NULL COMMENT '用户名',
  `real_name` varchar(50) DEFAULT NULL COMMENT '真实姓名',
  `password` varchar(60) NOT NULL COMMENT '密码',
  `enabled` bit(1) NOT NULL COMMENT '是否启用',
  `email` varchar(100) DEFAULT NULL COMMENT '邮箱',
  `created_by` varchar(50) DEFAULT NULL COMMENT '创建人',
  `created_date` timestamp NULL DEFAULT NULL COMMENT '创建日期',
  `last_modified_by` varchar(50) DEFAULT NULL COMMENT '最后更新人员',
  `last_modified_date` timestamp NULL DEFAULT NULL COMMENT '最后更新日期',
  `last_modified_ip` varchar(100) DEFAULT NULL COMMENT '最后登录ip',
  `entry_date` date DEFAULT NULL COMMENT '入职时间',
  `leave_date` date DEFAULT NULL COMMENT '离职时间',
  `avatar` varchar(50) DEFAULT NULL COMMENT '头像',
  PRIMARY KEY (`username`),
  UNIQUE KEY `un_users_emali` (`email`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='用户表';

-- ----------------------------
-- Records of users
-- ----------------------------
BEGIN;
INSERT INTO `users` VALUES ('admin', 'admin', '$2a$10$frZWT8/1KCEo7C9rm.8qCO.RBKnfJJ/YdKHmaFYoT93lTumLDqSiq', b'1', 'admin@qq.com', 'admin', '2020-01-30 02:51:18', 'admin', '2020-01-30 20:45:51', NULL, NULL, NULL, NULL);
COMMIT;

SET FOREIGN_KEY_CHECKS = 1;
